﻿using System;

namespace HashFoo.Rest.Common
{
    /// <summary>
    /// Defines the uri that is used for a <see cref="IResource"/>.
    /// </summary>
    public struct ResourceUri
    {
        /// <summary>
        /// The type of the resource.
        /// </summary>
        public Type ResourceType { get; set; }

        /// <summary>
        /// The uri linked to the resource.
        /// </summary>
        public string Uri { get; set; }

        /// <summary>
        /// Checks if two <see cref="ResourceUri"/>s are equal.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static bool operator ==(ResourceUri left, ResourceUri right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// Checks if two <see cref="ResourceUri"/>s are not equal.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static bool operator !=(ResourceUri left, ResourceUri right)
        {
            return !left.Equals(right);
        }

        /// <summary>
        /// Checks if this <see cref="ResourceUri"/> equals another.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (obj.GetType() != typeof(ResourceUri)) return false;
            return Equals((ResourceUri)obj);
        }

        /// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return (ResourceType != null ? ResourceType.GetHashCode() : 0);
        }

        /// <summary>
        /// Checks if this <see cref="ResourceUri"/> equals another.
        /// </summary>
        /// <returns></returns>
        public bool Equals(ResourceUri other)
        {
            return Equals(other.ResourceType, ResourceType);
        }
    }
}